package com.qianyu.project.core.mapper;

import com.qianyu.project.core.bean.FlowNode;
import com.qianyu.project.core.mapper.provider.FlowNodeProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author gs
 * @date create in 2020/12/11 16:02
 */
@Repository
public interface FlowNodeMapper {

    /**
     * description: 根据id查询节点 <br/>
     * author: gs   <br/>
     * date: 2020/12/12 <br/>
     * params: [flowNodeId] <br/>
     * return: com.qianyu.flow.core.pojo.FlowNode
     */
    @Select("select * from flow_node where flowNodeId=#{value}")
    FlowNode selectById(Integer flowNodeId);

    /**
     * description: 根据流程号查询第一个节点 <br/>
     * author: gs   <br/>
     * date: 2020/12/12 <br/>
     * params: [flowId] <br/>
     * return: com.qianyu.flow.core.pojo.FlowNode
     */
    @SelectProvider(type = FlowNodeProvider.class,method = "selectFirtstNode")
    FlowNode selectFirtstNode(Integer flowId);

    /**
     * description: 根据节点查询下一个节点 <br/>
     * author: gs   <br/>
     * date: 2020/12/12 <br/>
     * params: [flowNode] <br/>
     * return: com.qianyu.flow.core.pojo.FlowNode
     */
    @SelectProvider(type = FlowNodeProvider.class,method = "selectNextNode")
    FlowNode selectNextNode(FlowNode flowNode);

    @Select("select ${field} from ${target} where ${targetId}=#{id}")
    String selectTargetValue(Map<String, String> params);

    @Select("select * from flow_node where flowId = #{value} and isvalid =1")
    List<FlowNode> getListByFlowId(Integer flowId);

    @InsertProvider(method = "saveBatch",type = FlowNodeProvider.class)
    void saveBatch(List<FlowNode> nodeList);

    @Update("update flow_node set isvalid=0 where flowId  = #{value}")
    void updateBatch(Integer flowId);

    @Delete("delete from flow_node where flowId =#{value}")
    void delete(Integer flowId);
}
